package cn.edu.wdu.gaojie.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author gaojie  gao4433@qq.com
 * @Description JDBC 之【插入操作】
 * @date 2021/12/2 15:12
 * @since 1.8
 */
public class AppJdbcInsert {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");

        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        String userName = "root";
        String password = "778874315";
        Connection connection = DriverManager.getConnection(url, userName, password);

        Statement statement = connection.createStatement();
        String sql = "INSERT INTO `user` (`username`, `password`) VALUES ('charles', MD5('789'));";
        int i = statement.executeUpdate(sql);
        if (i > 0){
            System.out.println("插入成功！");
        }

    }
}
